package com.jeesite.modules.digitalize.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeesite.modules.digitalize.entity.DigitalizeMessage;
import com.jeesite.modules.digitalize.entity.dto.componentMessage.MessageQuery;
import com.jeesite.modules.digitalize.entity.dto.system.reviewproces.DeleteIdListDTO;
import com.jeesite.modules.digitalize.service.DigitalizeMessageService;
import com.jeesite.modules.digitalize.util.response.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author patronli
 * @Description:
 * @date 2023年08月31日 14:50:50
 */
@RestController
@Api(tags = "数字-消息")
@RequestMapping(value = "${adminPath}/digitalize/notice/")
public class NoticeController {
    @Resource
    private DigitalizeMessageService digitalizeMessageService;

    @ApiOperation("消息列表")
    @GetMapping("/pageList")
    public ResultVo<Page<DigitalizeMessage>> messages(@Validated MessageQuery query) {
        return digitalizeMessageService.pageList(query);
    }

    @ApiOperation("已读")
    @PostMapping("read")
    public ResultVo<Object> read(@RequestBody @Validated DeleteIdListDTO dto) {
        return digitalizeMessageService.read(dto.getIdList());
    }

    @ApiOperation("清空所有消息")
    @PostMapping("empty")
    public ResultVo<Object> empty() {
        return digitalizeMessageService.empty();
    }

    @ApiOperation("删除消息")
    @PostMapping("/delete")
    public ResultVo deleteList(@RequestBody @Validated DeleteIdListDTO dto) {
        return ResultVo.success(this.digitalizeMessageService.removeByIds(dto.getIdList()));
    }
}
